{extend name='index/index'/}
{block name="main"}
<style>
    .checkbox{
        margin-bottom: -5px;
        margin-top: 0;
    }
</style>
<div class="content">
    <div class="container">

        <!-- Page-Title -->
        <div class="row">
            <div class="col-sm-12">
                <h4 class="pull-left page-title">{$title}</h4>
                <ol class="breadcrumb pull-right">
                    <li>{$title}</li>
                    <li class="active">{$name}</li>
                </ol>
            </div>
        </div>


        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h4 class="panel-title">{$name}</h4>
                </div>
                <div class="panel-body">
                    <div class="inbox-widget nicescroll mx-box" tabindex="5000" style="overflow: hidden; outline: none;">

                        <a class="btn btn-success btn-icon btn-sm" href="{:url('advert/add')}"  rel="add"  >
                            <i class="md  md-add"></i>
                            <span>添加{$name}</span>
                        </a>

                        <a class="btn btn-danger btn-icon btn-sm" onclick="batchRemove()" >
                            <i class="md md-remove"></i>
                            <span>删除</span>
                        </a>
                        <div class="columns pull-right">
                            <button class="btn btn-success btn-sm" onclick="reLoad()">查询</button>
                        </div>
                        <div class="columns pull-right col-md-2 nopadding">
                            <input id="searchname" type="text" class="form-control"
                                   placeholder="商品名称">
                        </div>

                        <table class="table  table-striped" id="menuTable">

                        </table>
                    </div>
                </div>
            </div>
        </div>



        </div>
    </div>

<script src="__JS__/bootstrap-table/bootstrap-table.min.js"></script>
<script src="__JS__/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="__JS__/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script>
var detpId='';
load(detpId);
    function load(deptId) {
        $('#menuTable')
                .bootstrapTable(
                        {
                            method: "get",  //使用get请求到服务器获取数据
                            url: "{:url('advert/index')}", //获取数据的地址
                            striped: true,  //表格显示条纹
                            pagination: true, //启动分页
                            pageSize: 10,  //每页显示的记录数
                            pageNumber:1, //当前第几页
                            pageList: [5, 10, 15, 20, 25],  //记录数可选列表
                            sidePagination: "server", //表示服务端请求
                            paginationFirstText: "首页",
                            paginationPreText: "上一页",
                            paginationNextText: "下一页",
                            paginationLastText: "尾页",
                            queryParamsType : "undefined",



                            queryParams : function queryParamsType(params) {



                                var param = {
                                    pageNumber: params.pageNumber,
                                    pageSize: params.pageSize,
                                    searchText:$('#searchname').val()
                                };
                                return param;


                            },
                            columns : [
                                {
                                    checkbox : true
                                },
                                {
                                    field : 'id', // 列字段名
                                    title : '序号' // 列标题
                                },
                                {
                                    field : 'advert_name',
                                    title : '广告名称'
                                },
                                {
                                    field : 'cate_name',
                                    title : '所属分类'
                                },
                                {
                                    field : 'advert_urls',
                                    title : '链接地址'
                                },
                                {
                                    field : 'advert_img',
                                    title : '广告图片',
                                    formatter:function (value) {
                                        return '<img src="__UP__'+value+'" width="100" height="50"/>';
                                    }
                                },
                                {
                                    field : 'start_time',
                                    title : '开始时间',

                                },
                                {
                                    field : 'end_time',
                                    title : '结束时间'
                                },


                                {
                                    field : 'creattime',
                                    title : '创建时间'
                                },
                                {
                                    field : 'status',
                                    title : '状态',
                                    align : 'center',
                                    formatter : function(value, row, index) {
                                        if (value == '0') {
                                            return '<span class="label label-danger">禁用</span>';
                                        } else if (value == '1') {
                                            return '<span class="label label-primary">正常</span>';
                                        }
                                    }
                                },
                                {
                                    title : '操作',
                                    field : 'id',
                                    align : 'center',
                                    formatter : function(item, index) {

                                        var pid = item;

                                        var editother = "{:url('good/edit',array('id'=>'p_id'))}";

                                        var edit =  editother.replace("p_id",pid);


                                        var e="<a class='btn btn-pink waves-effect waves-light  btn-sm' rel='add' href='"+edit+"'><i class='fa fa-edit'></i> </a>&nbsp;";




                                        return e  ;
                                    }
                                } ],
                            onLoadSuccess: function(res){  //加载成功时执行
                                console.log(res);

                                layer.msg("加载成功", {time : 1000});
                            },
                            onLoadError: function(res){  //加载失败时执行
                                //console.log(res);
                                layer.msg("加载数据失败");
                            }

                        });
    }
    function reLoad() {
        $('#menuTable').bootstrapTable('refresh');
    }


   function batchRemove() {
       var rows = $('#menuTable').bootstrapTable('getSelections'); // 返回所有选择的行，当没有选择的记录时，返回一个空数组
       if (rows.length == 0) {
           swal({
               title: "请选择要删除的数据！",
               text: "",
               type: "error",
               timer: 2000,
               showConfirmButton: false
           });
           //layer.msg('请选择要删除的数据!');
         return;
       }

       swal({
                   title: "确认要删除选中的"+rows.length+"条数据吗？",
                   text: "删除过后你将无法恢复数据！",
                   type: "warning",
                   showCancelButton: true,
                   confirmButtonColor: "#DD6B55",
                   confirmButtonText: "确定删除！",
                   cancelButtonText: "取消",
                   closeOnConfirm: false
               },
               function(){
                   var ids = new Array();
                   $.each(rows, function(i, row) {
                    ids[i] = row['good_id'];
                  });

                   $.ajax({
                       type : 'POST',
                       data : {
                        "ids" : ids
                     },
                       url :"{:url('good/batchRemove')}",
                       success : function(r) {

                           if (r.code == 1) {

                               swal(r.msg, r.msg, "success");

                               reLoad();
                           }else{
                               swal(r.msg, r.msg, "error");

                           }
                       },
                       error:function (r) {
                           console.log(r.responseText);
                       }
                   });


               });






   }















</script>
{/block}